home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2009 February / PCWFEB09.iso / Software / Freeware / Griffith 0.9.8 / griffith-0.9.8-win32.exe / {app} / lib / plugins / movie / PluginMovieAniDB.py < prev    next >
Text File  |  2008-11-17  |  6KB  |  184 lines

  1. # -*- coding: utf-8 -*-
  2.  
  3. __revision__ = '$Id: PluginMovieAniDB.py 1040 2008-11-15 21:13:49Z mikej06 $'
  4.  
  5. # Copyright (c) 2005-2008 Piotr O┼╝arowski
  6. #
  7. # This program is free software; you can redistribute it and/or modify
  8. # it under the terms of the GNU General Public License as published by
  9. # the Free Software Foundation; either version 2 of the License, or
  10. # (at your option) any later version.
  11. #
  12. # This program is distributed in the hope that it will be useful,
  13. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  15. # GNU Library General Public License for more details.
  16. #
  17. # You should have received a copy of the GNU General Public License
  18. # along with this program; if not, write to the Free Software
  19. # 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
  20.  
  21. # You may use and distribute this software under the terms of the
  22. # GNU General Public License, version 2 or later
  23.  
  24. import gutils, movie
  25. import string, re
  26. from gutils import decompress
  27.  
  28. plugin_name         = 'AnimeDB'
  29. plugin_description  = 'Anime DataBase'
  30. plugin_url          = 'www.anidb.net'
  31. plugin_language     = _('English')
  32. plugin_author       = 'Piotr O┼╝arowski'
  33. plugin_author_email = '<ozarow+griffith@gmail.com>'
  34. plugin_version      = '2.5'
  35.  
  36. aid_pattern = re.compile('[?&;]aid=(\d+)')
  37.  
  38. class Plugin(movie.Movie):
  39.     def __init__(self, id):
  40.         self.encode = 'utf-8'
  41.         if string.find(id, 'http://') != -1:
  42.             self.url = str(id)
  43.             self.movie_id = 'anidb'
  44.         else:
  45.             self.movie_id = str(id)
  46.             self.url = "http://anidb.net/perl-bin/animedb.pl?show=anime&aid=%s" % self.movie_id
  47.  
  48.     def initialize(self):
  49.         self.page = decompress(self.page)
  50.         if self.movie_id == 'anidb':
  51.             aid =  aid_pattern.search(self.page)
  52.             if aid:
  53.                 self.movie_id = aid.groups()[0]
  54.                 self.url = "http://anidb.net/perl-bin/animedb.pl?show=anime&aid=%s" % self.movie_id
  55.             else:
  56.                 return False
  57.         self.page = gutils.after(self.page, 'id="layout-content"')
  58.         pos = string.find(self.page, 'class="g_section anime_episodes">')
  59.         if pos >0:
  60.             self.page = self.page[:pos]
  61.  
  62.     def get_image(self):
  63.         match = re.search('http://img\d*.anidb.net/pics/anime/\d*.jpg', self.page)
  64.         if match is not None:
  65.             self.image_url = match.group()
  66.         else:
  67.             self.image_url = ''
  68.  
  69.     def get_o_title(self):
  70.         self.o_title = gutils.trim(self.page, '<h1>Anime: ', '</h1>')
  71.  
  72.     def get_title(self):
  73.         self.title = gutils.trim(self.page, '"field">Official Title', '</td>')
  74.         self.title = gutils.trim(self.title, '<span>', '</span>')
  75.  
  76.     def get_director(self):
  77.         self.director = ''
  78.  
  79.     def get_plot(self):
  80.         self.plot = gutils.trim(self.page, 'class="desc">', '</div>')
  81.  
  82.     def get_year(self):
  83.         self.year = gutils.trim(self.page, '"field">Year', '</td>')
  84.         self.year = gutils.after(self.year, '"value">')[-4:]
  85.  
  86.     def get_runtime(self):
  87.         self.runtime = ''
  88.  
  89.     def get_genre(self):
  90.         self.genre = gutils.trim(self.page, '>Categories<', '</td>')
  91.         self.genre = gutils.after(self.genre, 'value">')
  92.         self.genre = gutils.strip_tags(self.genre)
  93.         if len(self.genre) and self.genre.endswith('- similar'):
  94.             self.genre =  self.genre[:-9]
  95.         elif self.genre == '-':
  96.             self.genre = ''
  97.         self.genre = string.replace(self.genre, '\n', '')
  98.  
  99.     def get_cast(self):
  100.         self.cast = ''
  101.  
  102.     def get_classification(self):
  103.         self.classification = ''
  104.  
  105.     def get_studio(self):
  106.         self.studio = gutils.trim(self.page, '"field">Producers', '</td>')
  107.         self.studio = gutils.strip_tags(self.studio)
  108.         if len(self.studio) and self.studio[:2] == " (":
  109.             self.studio = self.studio[2:]
  110.             if self.studio[len(self.studio)-1:] == ')':
  111.                 self.studio = self.studio[:len(self.studio)-1]
  112.         self.studio = string.replace(self.studio, '\n', '')
  113.  
  114.     def get_o_site(self):
  115.         self.o_site = gutils.trim(self.page, '"field">URL', '</td>')
  116.         self.o_site = gutils.trim(self.o_site, 'href="', '"')
  117.  
  118.     def get_site(self):
  119.         self.site = self.url
  120.  
  121.     def get_trailer(self):
  122.         self.trailer = ''
  123.  
  124.     def get_country(self):
  125.         self.country = ''
  126.  
  127.     def get_rating(self):
  128.         self.rating = gutils.trim(self.page, '"field">Rating', '</td>')
  129.  
  130.     def get_notes(self):
  131.         self.notes = ''
  132.         # ...type
  133.         atype = gutils.trim(self.page, '"field">Type', '</td>')
  134.         atype = gutils.clean(atype)
  135.         if atype != '':
  136.             self.notes += "Type: %s\n" % atype
  137.         # ...number of episodes
  138.         episodes = gutils.trim(self.page, '"field">Episodes', '</td>')
  139.         episodes = gutils.clean(episodes)
  140.         if episodes != '':
  141.             self.notes += "Episodes: %s\n" % episodes
  142.  
  143. class SearchPlugin(movie.SearchMovie):
  144.     def __init__(self):
  145.         self.encode = 'utf-8'
  146.         self.original_url_search    = 'http://anidb.net/perl-bin/animedb.pl?show=animelist&do.search=search&adb.search='
  147.         self.translated_url_search    = 'http://anidb.net/perl-bin/animedb.pl?show=animelist&do.search=search&adb.search='
  148.  
  149.     def search(self,parent_window):
  150.         self.open_search(parent_window)
  151.         self.page = decompress(self.page)
  152.  
  153.         tmp = string.find(self.page, '<h1>Anime List - Search for: ')
  154.         if tmp == -1:        # already a movie page
  155.             self.page = ''
  156.         else:            # multiple matches
  157.             self.page = gutils.trim(self.page, 'class="anime_list"', '</table>');
  158.             self.page = gutils.after(self.page, '</tr>');
  159.  
  160.         return self.page
  161.  
  162.     def get_searches(self):
  163.         if self.page == '':    # already a movie page
  164.             self.number_results = 1
  165.             self.ids.append(self.url)
  166.             self.titles.append(self.title)
  167.         else:            # multiple matches
  168.             elements = string.split(self.page,"</tr>")
  169.             self.number_results = elements[-1]
  170.  
  171.             if len(elements[0]):
  172.                 for element in elements:
  173.                     element = gutils.trim(element, '<td', '</td>')
  174.                     aid = aid_pattern.search(element)
  175.                     if not aid:
  176.                         continue
  177.                     self.ids.append(aid.groups()[0])
  178.                     element = gutils.after(element, '">')
  179.                     element = gutils.strip_tags(element)
  180.                     self.titles.append(element)
  181.             else:
  182.                 self.number_results = 0
  183.  
  184.